function formateDate(date){
  var date=new Date(date);
  return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDay();
 }



$.ajax({
    type:'get',
    url:'/posts/random',
    success:function(res){
        var randomTpl = `
			{{each data}}
			<li>
			  <a href="detail.html?id={{$value._id}}">
			    <p class="title">{{$value.title}}</p>
			    <p class="reading">阅读({{$value.meta.views}})</p>
			    <div class="pic">
			      <img src="{{$value.thumbnail}}" alt="">
			    </div>
			  </a>
			</li>
			{{/each}}
		`;
        var html=template.render(randomTpl,{data:res});
       
        $("#suiji").html(html);
    }
   
});

$.ajax({
    type:'get',
    url:'/comments/lasted',
    success:function(res){
      var comTpl=`
      {{each data}}
      <li>
            <a href="javascript:;">
              <div class="avatar">
                <img src="{{$value.author.avatar}}" alt="">
              </div>
              <div class="txt">
                <p>
                  <span>{{$value.author.nickName}}</span>{{$imports.formateDate($value.createAt)}}说:
                </p>
                <p>{{$value.content}}</p>
              </div>
            </a>
          </li>
      {{/each}}
      `
    var html= template.render(comTpl,{data:res});
    $("#commentss").html(html);
    }
});

$.ajax({
    type:'get',
    url:'/categories',
    success:function(res){
        var fenleiTpl=`
        {{each data}}
        <li><a href="list.html?categoryId={{$value._id}}">
        <i class="fa {{$value.className}}"></i>{{$value.title}}</a></li>
        {{/each}}
        `;
        var html=template.render(fenleiTpl,{data:res});
       
        $("#nav").html(html);
        $('#topNavBox').html(html)
    }
});
function getmessage(name) {
  var queryArr = location.search.substr(1).split('&');
  for (var i = 0; i < queryArr.length; i++) {
      var nameArr = queryArr[0].split("=")
      if (nameArr[0] == name) {
          return nameArr[1];
      }
  }
  return -1;

}


$('.search form').on('submit',function(){
  var keys=$(this).find('.keys').val();
  location.href='/search.html?key='+keys;
  return false;
})
